<template>
  <div>
    <div :class="className"
      :id="id"
      :style="{height:height,width:width}"></div>
  </div>
</template>
<script>
import echarts from 'echarts'
import EchartGl from 'echarts-gl/dist/echarts-gl.js'
// import resize from './mixins/resize.js'
import earth from '@/assets/images/earth.jpg'
import bathymetry_bw_composite_4k from '@/assets/images/bathymetry_bw_composite_4k.jpg'
import starfield from '@/assets/images/starfield.jpg'
import night from '@/assets/images/night.jpg'
import clouds from '@/assets/images/clouds.png'
export default {
  // mixins: [resize],
  name: 'globe-layers',
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    id: {
      type: String,
      default: 'globe'
    },
    width: {
      type: String,
      default: '1300px'
    },
    height: {
      type: String,
      default: '400px'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  methods: {
    initChart() {
      this.chart = echarts.init(document.getElementById(this.id))
      this.chart.setOption(
        {
          backgroundColor: '#000',
          globe: {
            baseTexture: earth,
            heightTexture: bathymetry_bw_composite_4k,
            displacementScale: 0.1,
            displacementQuality: 'ultra',
            shading: 'lambert',
            environment: starfield,
            light: {
              ambient: {
                intensity: 0.1
              },
              main: {
                intensity: 1.5
              }
            },
            layers: [
              {
                type: 'blend',
                blendTo: 'emission',
                texture: night
              },
              {
                type: 'overlay',
                texture: clouds,
                shading: 'lambert',
                distance: 5
              }
            ]
          },
          series: []
        },
        true
      )
    }
  },
  mounted() {
    // this.initChart()
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  }
}
</script>